package com.sgcc.fj.pmos.e_fj_order.activity;


import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.arouter.app.AppArouterPath;
import com.sgcc.fj.pmos.arouter.order.OrderArouterPath;
import com.sgcc.fj.pmos.common.base.MvpBaseRecycleActivity;
import com.sgcc.fj.pmos.common.utils.UserManager;
import com.sgcc.fj.pmos.e_fj_order.adapter.SupplementContractAdapter;
import com.sgcc.fj.pmos.e_fj_order.bean.SupplementContractBean;
import com.sgcc.fj.pmos.e_fj_order.contract.SupplementContract;
import com.sgcc.fj.pmos.e_fj_order.presenter.SupplementContractPresenter;

import java.util.List;

/**
 * @author ChaoAJ
 * @describe 补充协议
 * @time 2022/11/8 10:25
 */
@Route(path = OrderArouterPath.ORDER_SUPPLEMENTCONTRACT)
public class SupplementContractActivity extends MvpBaseRecycleActivity<SupplementContractBean.DataDTO,
        SupplementContractPresenter> implements SupplementContract.View {


    @Autowired
    public String relationId;

    @Autowired
    public boolean isAddBottomBtn;//是否显示上传补充协议按钮

    private SupplementContractAdapter supplementContractAdapter;

    @Override
    public String getTitleText() {
        return "补充协议";
    }

    @Override
    protected void initViews() {
        super.initViews();
        title_bar.setRightIcon(R.mipmap.go_main, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goMainActivity();
            }
        });
    }

    @Override
    public View getFooterLayout(RelativeLayout parent) {
        View footerView = getLayoutInflater().inflate(R.layout.footer_supplement_contract_layout, parent, false);
        if (isAddBottomBtn) {
            footerView.findViewById(R.id.tvAdd).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ARouter.getInstance()
                            .build(OrderArouterPath.ORDER_ADDSUPPLEMENTCONTRACT)
                            .withString("relationId", relationId)
                            .navigation(SupplementContractActivity.this,
                                    0x125);
                }
            });
            return footerView;
        } else {
            return super.getFooterLayout(parent);
        }
    }

    @Override
    public boolean isShowContent() {
        return true;
    }

    @Override
    public void getDataRequest(int listSize, boolean isloading) {
        super.getDataRequest(listSize, isloading);
        mPresenter.getSupplementContractList(relationId, true);
    }

    @Override
    public SupplementContractAdapter getAdapter() {
        supplementContractAdapter = new SupplementContractAdapter();
        onChangePage();
        return supplementContractAdapter;
    }

    @Override
    protected SupplementContractPresenter createPresenter() {
        return new SupplementContractPresenter();
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (RESULT_OK == resultCode) {
            if (requestCode == 0x125) {
                refresh(true);
            }
        }
    }

    @Override
    public void querySuccess(List<SupplementContractBean.DataDTO> list) {
        loadSuccess(false, list);
    }

    @Override
    public void queryFailed() {

    }


    private void onChangePage() {
        View notLoginView = View.inflate(mContext, R.layout.not_data_supplement_contract_layout, null);
        supplementContractAdapter.setEmptyView(notLoginView);
    }

}